package com.blacksea.authserver.service.manager;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.blacksea.authserver.dal.dataobject.UserDO;
import com.blacksea.authserver.service.repository.UserRepository;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * LoginManagerImpl
 *
 * @author blacksea3(jxt) 2021/4/17 19:36
 */
@Repository("loginManager")
public class LoginManagerImpl implements LoginManager {
    @Resource(name = "userRepository")
    private UserRepository userRepository;

    @Override
    public Pair<Boolean, String> verify(String username, String password) {
        if (userRepository.count(new LambdaQueryWrapper<UserDO>()
            .eq(UserDO::getUsername, username)
            .eq(UserDO::getPassword, password)
        ) == 1) {
            return new ImmutablePair<>(true, "");
        } else {
            return new ImmutablePair<>(false, "INVALID USER");
        }
    }
}
